<!-- @Author: Yu_Bo -->
<template>
	<view class="textbook">
		<c-goodslist :list="list" :type="2"></c-goodslist>
		<!-- 无数据 -->
		<c-emptydata :type="3" v-if="list.length == 0"></c-emptydata>
		<view class="mall_loading" v-if="list.length">
			<u-loadmore :status="status" color='#999' font-size='26' />
		</view>
		<!-- 底部按钮 -->
		<c-footer v-if="list.length">
			<view class="footer_btn">
				<view class="btn_txt color_right page_button" @click="addbookBtn">
					<u-loading v-if="loading" mode="flower" color="#ffffff"></u-loading>
					一键加入书包
				</view>
			</view>
		</c-footer>
	</view>
</template>

<script>
	import { mapState } from "vuex"
	export default {
		components: {},
		data() {
			return{
				list: [],
				loading: false,
			}
		},
		computed: {
			...mapState({
				userinfo: (state) => state.userinfo,
			}),
		},
		onLoad() {
			this.$nextTick(()=>{
				this.getObtain()
			})
		},
		onShow() {},
		methods: {
			// 立即获取
			getObtain() {
				var that = this
				var params = {
					college_id: that.userinfo.speciality_id,
					grade_id: that.userinfo.grade_id,
				}
				that.$httpApi.bookGoods(params).then((res) => {
					if (res.code == 1) {
						that.list=res.data
					}
				})
			},
			// 一键加入书包
			addbookBtn() {
				var that = this
				if(that.loading) return
				that.loading = true
				var arr = that.list.map((item)=>{return item.goods_id})
				var params = {
					goods_id: arr.join(",")
				}
				that.$httpApi.cartOneAdd(params).then((res) => {
					if (res.code == 1) {
						that.$tips.showToast(res.msg)
					}
				})
			},
		}
	}
</script>

<style lang='scss' scoped>
	.textbook {
		width: 100%;
		padding: 30rpx;
		
		.footer_btn {
			width: 100%;
			padding: 30rpx 30rpx;
			background: #fff;
			
			.btn_txt {
				width: 100%;
				height: 90rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				font-size: 32rpx;
				color: #FFFFFF;
				border-radius: 45rpx;
				display: flex;
				align-items: center;
				justify-content: center;
			}
		}
	}
</style>